<template>
    <IDrawer v-model="defaultValue" :loading="loading">
        <Form :model="data" :rules="ruleValidate" ref="formCreate">
            <ProductShowList v-model="data.products"></ProductShowList>
            <Row :gutter="12">
                <Col span="12">
                    <FormItem label="入库单号" prop="foreign">
                        <Input placeholder="入库单号" v-model="data.foreign"></Input>
                    </FormItem>
                </Col>
                <Col span="12">
                    <FormItem label="预计到货日期" prop="expect_at">
                        <DatePicker placeholder="预计到货日期" type="date" :value="data.expect_at" style="width: 100%;" @on-change="(v) => data.expect_at = v"></DatePicker>
                    </FormItem>
                </Col>
                <Col span="24">
                    <FormItem label="入库单备注" prop="remark">
                        <Input placeholder="入库单备注" type="textarea" :rows="5" :maxlength="200" v-model="data.remark"></Input>
                    </FormItem>
                </Col>
            </Row>
        </Form>
        <div slot="footer">
            <Button type="primary" icon="ios-add" @click="submit('formCreate')">提交</Button>
        </div>
    </IDrawer>
</template>

<script>
    import IDrawerMixins from "../../../../mixins/iDrawerMixins";
    import IDrawer from "../../../../components/layout/IDrawer";
    import IData from "./data"
    import ProductShowList from "./showList";

    export default {
        name: "update",
        components: {ProductShowList, IDrawer},
        mixins: [IDrawerMixins, IData],
        mounted() {
            this.getData();
        },
        methods: {
            submit(name){
                this.validate(name).then(() => {
                    this.loading = true;
                    this.$http.put(`entryorder/index/${this.props.id}`, this.data).then((res) => {
                        this.defaultValue = false;
                    }).finally(() => {
                        this.loading = false;
                    });
                }).catch();
            },
            getData(){
                this.loading = true;
                this.$http.get(`entryorder/index/${this.props.id}/edit`, this.data).then((res) => {
                    this.data = res;
                }).finally(() => {
                    this.loading = false;
                });
            }
        }
    }
</script>

<style scoped>

</style>
